package com.it.util;

import java.net.InetAddress;
import java.net.UnknownHostException;


public class GetIp {

    /**
     * This method works well in windows system.
     * In Linux system it returns 127.0.0.1 the content of the hosts file.
     */
    public static String getIpAddressInWindows() {
        String ip = "";
        try {
            InetAddress address = InetAddress.getLocalHost();
            ip = ip + address.getHostAddress();
        } catch (UnknownHostException e) {
            System.out.println("获取ip方法的异常");
            e.printStackTrace();
        } finally {
            return ip;
        }
    }


    public static void main(String[] args) {
        getIpAddressInWindows();
    }
}
